package com.xiguanlezz.cn.common.remote;

import com.xiguanlezz.cn.common.remote.client.RpcClient;
import com.xiguanlezz.cn.common.remote.client.grpc.GrpcClient;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/21 07:11
 * @Description：RPC客户端静态工厂类
 */
public class RpcClientFactory {
    private static final ConcurrentMap<String, RpcClient> CLIENT_MAP = new ConcurrentHashMap<>();

    public static RpcClient createClient(String clientName, ConnectionType connectionType, Map<String, String> labels) {
        if (!ConnectionType.GRPC.equals(connectionType)) {
            throw new UnsupportedOperationException("unsupported connection type :" + connectionType.getType());
        }
        return CLIENT_MAP.computeIfAbsent(clientName, (name) -> new GrpcClient(clientName, labels));
    }

}
